<template>
	<view>
		<view class="container">
			<view class="all_add">累计奖励 + {{topres}} 元</view>
			<!-- 带上拉加载的数据列表 -->
			<view class="big-loading-text loading-text ">
				<text>金额</text>
				<text>时间</text>
				<text>备注</text>
				<!-- <text>来源</text> -->
			</view>
			<!-- 数据列表 -->
			<view class="loading-text" v-for="(value,key) in newsList" :key="key">
				<text>{{value.money}}</text>
				<text>{{value.time}}</text>
				<text>{{value.remark}}</text>
				<!-- <text>{{value.comment}}</text> -->
			</view>
		</view>
		<uni-load-more v-if="load == 1" :loadingType="loadingType" :contentText="contentText"></uni-load-more>
	</view>
</template>

<script> 
	import uniLoadMore from '../../../components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				openid:'',
				systemInfo:[],
				active:"active",
				index:1,
				topres:1,
				newsList:[],
				loadingText: '加载中...',
				loadingType: 0,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				load: 0,
				page: 1,
				timer:{},
			}
		},
		onLoad: function(e) {
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.getnewsList()
					//页面一加载时请求一次数据`
					uni.hideLoading()
				},
				fail: () => {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			});
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getnewsList()
		},
		// 上拉加载
		onReachBottom(){
			if (this.timer != null) {
				clearTimeout(this.timer)
			}
			this.timer = setTimeout(()=> {
				this.getmorenews()
			}, 1000);
		},
		methods: {
			// 累计获得提成
			// setTopAjax(){
			// 	uni.request({
			// 		url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.putong_jicha&app=1',
			// 		method: 'POST',
			// 		data: {'openid':this.openid},
			// 		header:{'Content-Type':'application/x-www-form-urlencoded'},
			// 		success: (res) => {
			// 			// console.log(res)
			// 			this.topres = res.data.total
			// 		},
			// 		fail: () => {},
			// 		complete: () => {}
			// 	});
			// },
			// 上拉加载更多
			getmorenews() {
				this.page++;//每触底一次 page +1
				if (this.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				uni.request({
					url:'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.a_kzp&app=' + this.page,
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: function(res) {
						if (res.data.a_kzp == '') {//没有数据
							this.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}
						this.newsList = this.newsList.concat(res.data.a_kzp);//将数据拼接在一起
						this.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					}
				});
			},
			// 第一次请求数据，刷新
			
			getnewsList() {
				console.log(this.openid)
				// this.setTopAjax()
				this.loadingType = 0;
				uni.showNavigationBarLoading();
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.a_kzp&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => { 
						console.log(res)
						this.page++;//得到数据之后page+1
						this.topres = res.data.leiji_a_kzp;
						this.newsList = res.data.a_kzp;
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();//得到数据后停止下拉刷新
						// console.log(this.newsList)
					}
				});
			},
		},
	}
</script>

<style>
.container {
	background-color: #FEA23D;
}
.loading-text {
	margin: ;
	background-color: fff;
	display: flex;
}

.loading-text text:nth-child(1) {
	padding-left: 15upx;
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(2) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 3;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(3) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 2;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(4) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 5;
	text-align: center;
	font-size: 26upx;
}
.all_add {
	height: 80upx;
	text-align: center;
	line-height: 80upx;
	background-color: rgb(254,162,61);
	color: #fff;
}
.big-loading-text {
	font-weight: 550;
	border-bottom: 2upx solid rgb(243,243,243);
}
uni-page-body{height:100%;}
</style>

